package com.lanyam.travel.base.controller;

import com.lanyam.travel.base.entity.DataStatistics;
import com.lanyam.travel.base.service.IDataStatisticsService;
import com.lanyam.travel.base.utils.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 版权所有： 稻草人
 * 创建者： wenhe
 * 创建时间: 2020-02-04
 * 描述：统计数据获取接口
 * 其它：
 **/
@RestController
@RequestMapping(value="/dataStatistics")
public class DataStatisticsController {

    @Autowired
    private IDataStatisticsService dataStatisticsService;

    /**
     * 获取统计图表数据
     * @param dataStatistics
     *      dimension : 统计维度
     *      mapperName: 调用的mapper名称
     *      chartType : 图表类型
     *      queryParams: 请求参数
     * @return
     */
    @PostMapping(value="/getData")
    public JSONResult getData(@RequestBody DataStatistics dataStatistics) {
        JSONResult result = null;
        try {
            Map dataStatisticsMap = dataStatisticsService.getDataStatistics(dataStatistics);
            result = JSONResult.ok(dataStatisticsMap);
        } catch (Exception e) {
            e.printStackTrace();
            result = JSONResult.errorMsg(e.getMessage());
        }
        return result;
    }

    @PostMapping(value="/getOrderCount")
    public JSONResult getOrderCount() {
        JSONResult result = null;
        try {
            Map dataStatisticsMap = dataStatisticsService.getOrderCount();
            result = JSONResult.ok(dataStatisticsMap);
        } catch (Exception e) {
            e.printStackTrace();
            result = JSONResult.errorMsg(e.getMessage());
        }
        return result;
    }
}
